<template>
  <!--模态窗 单行-->
  <transition
    name="custom-classes-transition"
    enter-active-class="animated fadeInDown"
    leave-active-class="animated fadeOutUp"
  >
    <div class="modal-ctrl-body" v-show="addModalObj.isShow">
      <div class="modal-ctrl-main odd-row-ctrl">
        <div class="modal-title">
          <p>新增应急物资信息</p>
        </div>
        <div class="modal-ctrl-content">

          <div class="modal-row">
            <div class="modal-form-key f-l indispensable">
              物资名称：
            </div>
            <input type="text" maxlength="16" placeholder="最长16个字符" v-model="AddData.NAME" class="modal-text f-l">
          </div>

          <div class="modal-row">
            <div class="modal-form-key f-l indispensable">
              物资数量：
            </div>
            <input type="text" maxlength="16" placeholder="最长16个字符" v-model="AddData.NUM" class="modal-text f-l">
          </div>

        </div>
        <div class="btns text-r">
          <button type="button" class="btn btn-default" @click="closeRoleModal">取消</button>
          <button type="button" class="btn btn-info" @click="subFn">确定</button>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
    export default {
        name: "AddCaseResourceModal",
        props:["addModalObj"],
        data(){
          return{
            AddData:{
              NAME:"",//名称
              NUM:"",//数量
              CREATE_TIME:"",//创建时间
              CREATE_USER:"",//创建人
            }
          }
        },
        methods:{
          subFn(){
            this.AddData.CREATE_USER = this.isLogin().userId;
            //console.log(this.AddData);
            let params = {
              "columns": [],
              "dataTypeCode": "pointresource",
              "datas": [],
              "tableName": "T_EMERGENCY_FACILITY"
            };
          /*  for( let paramsKey in this.AddData ){
              this.AddData[paramsKey] = this.JPtool.subBlank(this.AddData[paramsKey]);
            }*/
            this.AddData.NAME = this.JPtool.subBlank(this.AddData.NAME);
            this.AddData.NUM = this.JPtool.subBlank(this.AddData.NUM);
            if( this.verifyForm.isNull(this.AddData.NAME) ){
              this.s_alert("物资名称不能为空！");
              return false;
            }else if( this.verifyForm.isNull(this.AddData.NUM) || this.verifyForm.isNumber(this.AddData.NUM) ){
              this.s_alert("物资数量为空或者格式不正确！只能为整数！");
              return false;
            }

            for( let Key in this.AddData ){
              params["columns"].push(Key);
              params["datas"].push(this.AddData[Key]);
            }

            this.$axios.post(this.HOST+"/base/save",params)
              .then(res=>{
                if( res.data.success === true ){
                  this.s_alert("新增预案物资成功！");
                  this.s_logwrite("预案管理-预案物资管理","新增物资");
                  this.closeRoleModal();
                }
              })
              .catch(err=>{
                this.s_alert("新增预案物资失败！");
                //console.log(err);
              })
          },
          //清除缓存
          clearData(){
            this.AddData={
              NAME:"",//名称
              NUM:"",//数量
            }
          },
          //关闭弹窗
          closeRoleModal(){
            this.clearData();
            this.$emit("closeModal");
          }
        }
    }
</script>

<style scoped>
  .fadeInDown,.fadeOutUp{
    animation-duration: .500s;
  }
</style>
